package com.yuanqi.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import lombok.Data;

/**
 * 库存余额
 * @TableName inventory
 */
@TableName(value ="inventory")
@Data
public class Inventory implements Serializable {
    /**
     * 主键
     */
    @TableId(type = IdType.AUTO)
    private Long id;

    /**
     * 仓库ID
     */
    private Long warehouseId;

    /**
     * 库位ID
     */
    private Long locationId;

    /**
     * SKU ID
     */
    private Long skuId;

    /**
     * 批次号（启用批次时必填）
     */
    private String batchNo;

    /**
     * 有效期（如启用批次/效期）
     */
    private Date expiryDate;

    /**
     * 账面在库数量
     */
    private BigDecimal onHandQty;

    /**
     * 可用数量=在库-占用
     */
    private BigDecimal availableQty;

    /**
     * 占用数量
     */
    private BigDecimal occupiedQty;

    /**
     * 最新更新时间
     */
    private Date updatedAt;

    /**
     * 批次号归一化（NULL->空串）- 数据库生成列，不参与ORM操作
     */
    @TableField(exist = false)
    private String batchNoNorm;

    @TableField(exist = false)
    private static final long serialVersionUID = 1L;

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        Inventory other = (Inventory) that;
        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
            && (this.getWarehouseId() == null ? other.getWarehouseId() == null : this.getWarehouseId().equals(other.getWarehouseId()))
            && (this.getLocationId() == null ? other.getLocationId() == null : this.getLocationId().equals(other.getLocationId()))
            && (this.getSkuId() == null ? other.getSkuId() == null : this.getSkuId().equals(other.getSkuId()))
            && (this.getBatchNo() == null ? other.getBatchNo() == null : this.getBatchNo().equals(other.getBatchNo()))
            && (this.getExpiryDate() == null ? other.getExpiryDate() == null : this.getExpiryDate().equals(other.getExpiryDate()))
            && (this.getOnHandQty() == null ? other.getOnHandQty() == null : this.getOnHandQty().equals(other.getOnHandQty()))
            && (this.getAvailableQty() == null ? other.getAvailableQty() == null : this.getAvailableQty().equals(other.getAvailableQty()))
            && (this.getOccupiedQty() == null ? other.getOccupiedQty() == null : this.getOccupiedQty().equals(other.getOccupiedQty()))
            && (this.getUpdatedAt() == null ? other.getUpdatedAt() == null : this.getUpdatedAt().equals(other.getUpdatedAt()))
            && (this.getBatchNoNorm() == null ? other.getBatchNoNorm() == null : this.getBatchNoNorm().equals(other.getBatchNoNorm()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
        result = prime * result + ((getWarehouseId() == null) ? 0 : getWarehouseId().hashCode());
        result = prime * result + ((getLocationId() == null) ? 0 : getLocationId().hashCode());
        result = prime * result + ((getSkuId() == null) ? 0 : getSkuId().hashCode());
        result = prime * result + ((getBatchNo() == null) ? 0 : getBatchNo().hashCode());
        result = prime * result + ((getExpiryDate() == null) ? 0 : getExpiryDate().hashCode());
        result = prime * result + ((getOnHandQty() == null) ? 0 : getOnHandQty().hashCode());
        result = prime * result + ((getAvailableQty() == null) ? 0 : getAvailableQty().hashCode());
        result = prime * result + ((getOccupiedQty() == null) ? 0 : getOccupiedQty().hashCode());
        result = prime * result + ((getUpdatedAt() == null) ? 0 : getUpdatedAt().hashCode());
        result = prime * result + ((getBatchNoNorm() == null) ? 0 : getBatchNoNorm().hashCode());
        return result;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", id=").append(id);
        sb.append(", warehouseId=").append(warehouseId);
        sb.append(", locationId=").append(locationId);
        sb.append(", skuId=").append(skuId);
        sb.append(", batchNo=").append(batchNo);
        sb.append(", expiryDate=").append(expiryDate);
        sb.append(", onHandQty=").append(onHandQty);
        sb.append(", availableQty=").append(availableQty);
        sb.append(", occupiedQty=").append(occupiedQty);
        sb.append(", updatedAt=").append(updatedAt);
        sb.append(", batchNoNorm=").append(batchNoNorm);
        sb.append(", serialVersionUID=").append(serialVersionUID);
        sb.append("]");
        return sb.toString();
    }
}